package sourceagile.webservices.github;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jettison.json.JSONObject;

import sourceagile.server.gitFileRepository.GetGitClassFileTEMP;
import sourceagile.server.githubFileRepository.GetGithubClassFile;
import sourceagile.webservices.GetCallback;

@SuppressWarnings("serial")
public class GetGithubClassDocumentServlet extends HttpServlet {

	// http://localhost:8080/LiveSourceWebServices/GetGithubClassDocumentService
	// ?projectName=TravelLog
	// &username=allineo
	// &sha=c2278fdc2f83aad7943a350d3d37ad7dd6d0ef63
	// &filePath=src/com/amazon/aws/samplecode/travellog/entity/Comment.java

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		String projectName = request.getParameter("projectName");

		String username = request.getParameter("username");

		String password = request.getParameter("password");

		String objectSHA = request.getParameter("sha");

		String filePath = request.getParameter("filePath");

		GetGitClassFileTEMP.jsonClassDocument();

		/*
		 * JSONObject fileContent = GetGitClassFile.jsonClassDocument(username,
		 * projectName, objectSHA, filePath);
		 * 
		 * String answer = GetCallback.getCallback(
		 * request.getParameter("callback"), fileContent.toString());
		 * 
		 * response.setContentType("text/javascript");
		 * 
		 * response.getWriter().println(answer);
		 */

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		String projectName = request.getParameter("projectName");

		String username = request.getParameter("username");

		String password = request.getParameter("password");

		String objectSHA = request.getParameter("sha");

		String filePath = request.getParameter("filePath");

		JSONObject fileContent = GetGithubClassFile.jsonClassDocument(username,
				projectName, objectSHA, filePath);

		String answer = GetCallback.getCallback(
				request.getParameter("callback"), fileContent.toString());

		response.setContentType("text/javascript");

		response.getWriter().println(answer);
	}
}
